﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ExtAspNet;

namespace HY.WEB.OA
{
    public partial class hrad_edit : PageBase
    {

        string sid = "";
        public string us;
        protected void Page_Load(object sender, EventArgs e)
        {
            us = Session["ID"].ToString();

            if (!IsPostBack)
            {
                if (!string.IsNullOrEmpty(Request["sid"]))
                {
                    sid = Request["sid"].Trim();
                    Fill(sid);
                }
            }
            
        }


        void Fill(string sid)
        {
            DataTable dt = BLL.oa.ad.get_view("sid=" + sid);

            if (dt.Rows.Count > 0)
            {
                txttitel.Text = dt.Rows[0]["adtitle"].ToString();
                txtday.Text = dt.Rows[0]["adday"].ToString();
                FCKeditor1.Value =HttpUtility.HtmlDecode( dt.Rows[0]["adcontents"].ToString());
                hidsid.Text = sid;

                if (dt.Rows[0]["adtype"].ToString() == "PP")
                    txtday.Visible = false;

            }

        }


      

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string title = txttitel.Text;
            string fileName = "";
            string path = "";
            try
            {
                 fileName = fileup.ShortFileName;

                 fileName = fileName.Replace(":", "_").Replace(" ", "_").Replace("\\", "_").Replace("/", "_");
                            fileName = DateTime.Now.Ticks.ToString() + "_" + fileName;
                             path = "~/file/oa/" + fileName;
                            if (fileup.HasFile)
                                fileup.SaveAs(Server.MapPath(path));

            }catch(Exception ex)
            {}
           finally
            {} 
            


            string person = Session["user"].ToString();
            string day = txtday.Text;
            string memo = HttpUtility.HtmlEncode(FCKeditor1.Value);
            sid = hidsid.Text;
            BLL.oa.ad.update_ad(sid,title, day, memo, path);

            //Alert.Show("修改完成 ");
            PageContext.RegisterStartupScript(ActiveWindow.GetHideReference());
        }

       
    }
}